﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.货号管理.service;
using DevExpress.XtraGrid.Demos.util;
using DevExpress.Utils.Win;
using DevExpress.XtraEditors.Popup;
using DevExpress.XtraGrid.Editors;
using DevExpress.XtraLayout;
using System.IO;

namespace DXApplicationTangche.UC.货号管理
{
    public partial class Form外观设计 : DevExpress.XtraEditors.XtraForm
    {
        public String id { get; set; }
        private List<CraftDesignItemDTO> craftDesignItemDTOs = new List<CraftDesignItemDTO>();
        private GarmentPartDTO GarmentPartDTO = new GarmentPartDTO();
        private String sessionId;
        public String facadeFileName { get; set; }
        public Form外观设计(String facadeFileName, Image facadePicture)
        {
            InitializeComponent();
            this.sessionId = new FunctionHelper().Uuid;
            this.facadeFileName = facadeFileName;
            this.textBoxitemNameCn.Text = Path.GetFileNameWithoutExtension(this.facadeFileName);
            this.pictureBox设计点.Image = facadePicture;
            //this.searchLookUpEdit选择位置.Properties.DataSource = 款式迭代Service.getAllGarmentPartDaos();
            this.addCraftDesignItemDTOs();
            this.loadGrid();
        }
        public Form外观设计()
        {
            InitializeComponent();
            this.sessionId = new FunctionHelper().Uuid;
            this.addCraftDesignItemDTOs();
            this.loadGrid();

        }
        private void simpleButton确定_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(this.textBoxitemTypeName.Text.Trim())
                || String.IsNullOrWhiteSpace(this.textBoxitemCd.Text.Trim()) 
                || String.IsNullOrWhiteSpace(this.textBoxitemValue.Text.Trim()) 
                || String.IsNullOrWhiteSpace(this.textBoxitemNameCn.Text.Trim())
                )
            {
                MessageBox.Show("请将设计点相关信息填写完整");
                return;
            }
            try
            {
                this.id = 款式迭代Service.saveCraftFacadeDesign(
                                      this.sessionId,
                                      this.textBoxitemCd.Text.Trim(),
                                      this.textBoxitemTypeName.Text.Trim(),
                                      this.textBoxitemValue.Text.Trim(),
                                      this.textBoxitemNameCn.Text.Trim());
                //String re2 = 款式迭代Service.saveCraftFacadeDesinFile(
                //    this.sessionId,
                //    this.facadeFileName
                //    );
                MessageBox.Show("保存成功");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存失败");
            }
        }

        #region 选择位置
        //private void searchLookUpEdit选择位置_Popup(object sender, EventArgs e)
        //{
        //    PopupSearchLookUpEditForm form = (sender as IPopupControl).PopupWindow as PopupSearchLookUpEditForm;
        //    SearchEditLookUpPopup popup = form.Controls.OfType<SearchEditLookUpPopup>().FirstOrDefault();
        //    LayoutControl layout = popup.Controls.OfType<LayoutControl>().FirstOrDefault();
        //    //如果窗体内空间没有确认按钮，则自定义确认simplebutton，取消simplebutton，选中结果label
        //    if (layout.Controls.OfType<Control>().Where(ct => ct.Name == "btOK").FirstOrDefault() == null)
        //    {
        //        //得到空的空间
        //        EmptySpaceItem a = layout.Items.Where(it => it.TypeName == "EmptySpaceItem").FirstOrDefault() as EmptySpaceItem;

        //        //得到取消按钮，重写点击事件
        //        Control clearBtn = layout.Controls.OfType<Control>().Where(ct => ct.Name == "btClear").FirstOrDefault();
        //        LayoutControlItem clearLCI = (LayoutControlItem)layout.GetItemByControl(clearBtn);
        //        clearBtn.Click += clearBtn位置_Click;

        //        //添加一个simplebutton控件(确认按钮)
        //        LayoutControlItem myLCI = (LayoutControlItem)clearLCI.Owner.CreateLayoutItem(clearLCI.Parent);
        //        myLCI.TextVisible = false;
        //    }
        //}
        //private void searchLookUpEdit选择位置View_Click(object sender, EventArgs e)
        //{
        //    int[] a = this.searchLookUpEdit选择位置.Properties.View.GetSelectedRows();
        //    if (a.Length > 0)
        //    {
        //        foreach (int rowHandle in a)
        //        {
        //            this.partId = this.searchLookUpEdit选择位置.Properties.View.GetRowCellValue(rowHandle, "id").ToString();
        //            this.partDesc = this.searchLookUpEdit选择位置.Properties.View.GetRowCellValue(rowHandle, "partDesc").ToString();
        //        }
        //    }
        //}

        ///// <summary>
        ///// 清除按钮事件
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //private void clearBtn位置_Click(object sender, EventArgs e)
        //{
        //    this.searchLookUpEdit选择位置.ToolTip = null;
        //    searchLookUpEdit选择位置.EditValue = null;
        //}
        //private void searchLookUpEdit选择位置_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
        //{
        //    if (null != e.Value)
        //        e.DisplayText = this.partDesc;
        //}
        #endregion

        private void addCraftDesignItemDTOs()
        {
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("审版", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("调版", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("裁断", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("粘衬", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("车间", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("半成手缝", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("特种", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("成品手缝", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("检查", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("销售", false));
        }

        public void loadGrid()
        {
            this.gridControl工序要求.DataSource = this.craftDesignItemDTOs;
            this.gridView工序要求.RefreshData();
        }
    }
}